package com.wu.gumomallproduct.product.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "task.pool")
public class ThreadPoolProperties {
    /**
     * 核心线程数（默认线程数）
     */
    private int corePoolSize = 10;
    
    /**
     * 最大线程数
     */
    private int maxPoolSize = 20;
    
    /**
     * 队列容量
     */
    private int queueCapacity = 200;
    
    /**
     * 允许线程空闲时间（单位：秒）
     */
    private int keepAliveSeconds = 60;
    
    /**
     * 线程名称前缀
     */
    private String threadNamePrefix = "Async-Service-";
    
    /**
     * 是否允许核心线程超时
     */
    private boolean allowCoreThreadTimeOut = false;
    
    /**
     * 等待所有任务完成后才关闭线程池
     */
    private boolean waitForTasksToCompleteOnShutdown = true;
    
    /**
     * 等待终止的最大时间（单位：秒）
     */
    private int awaitTerminationSeconds = 60;
    
    /**
     * 拒绝策略
     * AbortPolicy: 直接抛出异常
     * CallerRunsPolicy: 由调用线程处理该任务
     * DiscardPolicy: 丢弃当前任务
     * DiscardOldestPolicy: 丢弃队列中最老的任务
     */
    private String rejectedExecutionHandler = "CallerRunsPolicy";

    // Getters and Setters
    public int getCorePoolSize() {
        return corePoolSize;
    }

    public void setCorePoolSize(int corePoolSize) {
        this.corePoolSize = corePoolSize;
    }

    public int getMaxPoolSize() {
        return maxPoolSize;
    }

    public void setMaxPoolSize(int maxPoolSize) {
        this.maxPoolSize = maxPoolSize;
    }

    public int getQueueCapacity() {
        return queueCapacity;
    }

    public void setQueueCapacity(int queueCapacity) {
        this.queueCapacity = queueCapacity;
    }

    public int getKeepAliveSeconds() {
        return keepAliveSeconds;
    }

    public void setKeepAliveSeconds(int keepAliveSeconds) {
        this.keepAliveSeconds = keepAliveSeconds;
    }

    public String getThreadNamePrefix() {
        return threadNamePrefix;
    }

    public void setThreadNamePrefix(String threadNamePrefix) {
        this.threadNamePrefix = threadNamePrefix;
    }

    public boolean isAllowCoreThreadTimeOut() {
        return allowCoreThreadTimeOut;
    }

    public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) {
        this.allowCoreThreadTimeOut = allowCoreThreadTimeOut;
    }

    public boolean isWaitForTasksToCompleteOnShutdown() {
        return waitForTasksToCompleteOnShutdown;
    }

    public void setWaitForTasksToCompleteOnShutdown(boolean waitForTasksToCompleteOnShutdown) {
        this.waitForTasksToCompleteOnShutdown = waitForTasksToCompleteOnShutdown;
    }

    public int getAwaitTerminationSeconds() {
        return awaitTerminationSeconds;
    }

    public void setAwaitTerminationSeconds(int awaitTerminationSeconds) {
        this.awaitTerminationSeconds = awaitTerminationSeconds;
    }

    public String getRejectedExecutionHandler() {
        return rejectedExecutionHandler;
    }

    public void setRejectedExecutionHandler(String rejectedExecutionHandler) {
        this.rejectedExecutionHandler = rejectedExecutionHandler;
    }
}